#ifndef CROUTECONDITIONS_H
#define CROUTECONDITIONS_H

#include "common.h"
#include "singleton.h"
#include "cjson.h"
#include "wbasenode.h"
#include "wsignallampnode.h"
#include "wswitchnode.h"

struct tagSwitchCondiItem
{
    tagSwitchCondiItem():switchnode(NULL),switchstate(SwitchState::NOINIT) {}
    tagSwitchCondiItem(WSwitchNode *node,SwitchState sstate)
        : switchnode(node),switchstate(sstate) {}

    WSwitchNode *switchnode;
    int switchstate;
};

struct tagRouteCondiItem
{
    wxString startLight;                           // 开始灯
    wxString endLight;                             // 结束灯
    wxVector<WSignalLampNode*> conflictsignals;    // 敌对信号灯
    wxVector<tagSwitchCondiItem> conflictswitch;   // 敌对道岔
    wxVector<tagSwitchCondiItem> followswitch;     // 带动道岔
};

class CRouteConditions : public Singleton<CRouteConditions>
{
public:
    CRouteConditions();
    ~CRouteConditions();

    /// 解析Json
    void parsingJson(cJSON *routecondi);
    /// 添加一个进路条件到系统中
    void addRouteCondiItem(tagRouteCondiItem pRouteCondiItem);
    /// 得到指定进路的敌对条件
    const tagRouteCondiItem* getRouteCondiItem(wxString startNode,wxString endNode);
    /// 得到所有的进路关系
    inline std::map<wxString,std::map<wxString,tagRouteCondiItem>> getAllRouteConditions(void) { return m_RouteConditions; }

private:
    std::map<wxString,std::map<wxString,tagRouteCondiItem>> m_RouteConditions;
};

#endif // CROUTECONDITIONS_H
